<?php
include_once "db.php";

      if($_POST[f_name] == "") {
   $error = "true";
   $_POST[f_name] = "error";
  }
  
  if($_POST[l_name] == "") {
   $error = "true";
   $_POST[l_name] = "error";
  }

   if($_POST[email] == "") {
   $error = "true";
   $_POST[email] = "error";
  } 
 
   if($_POST[problem_type] == "") {
   $error = "true";
   $_POST[problem_type] = "error";
  } 
  
  if($_POST[Platform] == "") {
   $error = "true";
   $_POST[Platform] = "error";
  }
  
  if($_POST[browser] == "") {
   $error = "true";
   $_POST[browser] = "error";
  }
  
   if($_POST[operating_system] == "") {
   $error = "true";
   $_POST[operating_system] = "error";
  } 
 
   //if($_POST[course] == "") {
  // $error = "true";
  // $_POST[course] = "error";
 // } 
  
    if($_POST[pipeline_reset] != "1" && $_POST[pipeline_reset2] != "2" ) {
   $error = "true";
   $_POST[pipeline_reset] = "error";
  } 
  
   
  
    if($_POST[Problem] == "") {
   $error = "true";
   $_POST[Problem] = "error";
  } 
    if($_POST[notes] == "") {
   $error = "true";
   $_POST[notes] = "error";
  }
  
    if($_POST[call_closed] == "") {
   $error = "true";
   $_POST[call_closed] = "error";
  }

   if ($error) {
  header("Location: newcall.php?error=true&f_name=$_POST[f_name]&l_name=$_POST[l_name]&email=$_POST[email]&problem_type=$_POST[problem_type]&Platform=$_POST[Platform]&browser=$_POST[browser]&operating_system=$_POST[operating_system]&course=$_POST[course]&pipeline_reset=$_POST[pipeline_reset]&vista_reset=$_POST[vista_reset]&Problem=$_POST[Problem]&notes=$_POST[notes]&call_closed=$_POST[call_closed]");
 }
 else {
  
	mysql_query ("insert into Calls (first_name, m_initial, last_name, other_name, pipeline_userid, day_phone, birthdate, problem_desc, email, problem_type, os_type, browser_type, computer_type, left_mssg, course, semester, call_closed, helpdesk_user, higher_level, pending) values('$_POST[f_name]', '$_POST[m_initial]','$_POST[l_name]', '$_POST[o_name]', '$_POST[userid]', '$_POST[dayphone]', '$_POST[birthdate]', '$_POST[Problem]', '$_POST[email]', '$_POST[problem_type]', '$_POST[operating_system]' , '$_POST[browser]', '$_POST[Platform]', '$_POST[call]',  '$_POST[course]', '$_POST[semester]', '$_POST[call_closed]', '$_POST[HDuserID]', '$_POST[high_level]', '$_POST[pending]')");
	
$id = mysql_insert_id();
	
	mysql_query ("insert into resolution_notes (call_ID, HD_user_ID, note_desc, contact_type, pipeline_reset, vista_reset) values ('$id', '$_POST[HDuserID]', '$_POST[notes]', '$_POST[contact_type]', '$_POST[pipeline_reset]', '$_POST[vista_reset]' )"); 

// opening connections to the various dbse tables to retrieve descriptions associated with items and set returned data into variables for email 
$browser = mysql_query("select * from browser_type where BT_ID LIKE '$_POST[browser]'");
$user_browser= mysql_fetch_object($browser) ;
$user_browser->BT_desc ;
$computer = mysql_query("select * from computer_type where CT_ID LIKE '$_POST[Platform]'");
$user_computer= mysql_fetch_object($computer) ;
$user_computer->CT_desc ;
$problem = mysql_query("select * from problem_type where PT_ID LIKE '$_POST[problem_type]'");
$user_problem= mysql_fetch_object($problem) ;
$user_problem->PT_desc ;
$os = mysql_query("select * from operating_system where os_id LIKE '$_POST[operating_system]'");
$user_os= mysql_fetch_object($os) ;
$user_os->os_desc ;
$course = mysql_query("select * from current_courses where ID LIKE '$_POST[course]'");
$user_course= mysql_fetch_array($course) ;
 	$course_title = $user_course[course_title];
    $course_num = $user_course[course_number];
	$course_section = $user_course[section];

 if ($_POST[call]=1) 
   $call = "yes";
 else if ($_POST[call]=2) 
 	$call = "no";
	
//Send Email
$to = "Online Support < online@sbcc.edu >";

// subject
$subject = "WebForm-" .$user_problem->PT_desc ;

// message
$message = "First Name: " .$_POST[f_name]. "\n\n";
$message .= "Last Name:".$_POST[l_name]."\n\n" ;
$message .= "Other Name:".$_POST[o_name]."\n\n" ;
$message .= "UserID:" .$_POST[userid]. "\n\n" ;
$message .= "Phone:" .$_POST[dayphone]."\n\n" ;
$message .= "Problem:" .$_POST[Problem]."\n\n" ;
$message .= "Email:" .$_POST[email]. "\n\n" ;
$message .= "Problem Type:" .$user_problem->PT_desc . "\n\n" ;
$message .= "Operating System:" .$user_os->os_desc . "\n\n" ;
$message .= "Browser:" .$user_browser->BT_desc. "\n\n" ;
$message .= "Platform:" .$user_computer->CT_desc . "\n\n" ;
$message .= "Called Helpdesk?:" .$call. "\n\n" ;
$message .= "Course:" .$course_num. "-" .$course_title. " "  .$course_section. "\n\n" ;
$message .= "Semester:" .$_POST[semester]. "\n\n" ;

$headers = "From: " . $_POST[email] ;
$headers .= "\r\nContent-type: text/plain";

// Mail it
mail($to, $subject, $message, $headers);
header("Location: index.php");
  

}
?>